﻿<?php
require 'cle_encrypt.php';
include 'config.php';

$uname = $_REQUEST["name"];
$upass = $_REQUEST["thePass"];

$sql =  " select e.id, e.firstName, e.lastName,  e.title, e.departement, e.city, e.officePhone, e.cellPhone, e.email, e.picture  " .
		" from employee_vw e " .
		" where e.id= :theid  AND EXISTS ( SELECT * FROM t001_users where id = get_user_id( :uname, AES_ENCRYPT(:upass ,:cle_encrypt)) ) " ;

try {
	$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));	
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$stmt = $dbh->prepare($sql);  

	$stmt->bindParam("theid", $_GET["id"]);
	$stmt->bindParam("uname", $uname);
	$stmt->bindParam("upass", $upass);
	$stmt->bindParam("cle_encrypt", $cle_encrypt);
	
	$stmt->execute();
	$employee = $stmt->fetchObject();
	$dbh = null;
	
	echo '{"item":'. json_encode($employee) .'}'; 
	
} catch(PDOException $e) {
	echo '{"error":{"text":'. $e->getMessage() .'}}'; 
}

?>